import rxAjax from '@/assets/js/ajax.js';

export const OsUserApi = {};

OsUserApi.baseUrl= '/api-user/user/org/osUser';
OsUserApi.exportUrl= OsUserApi.baseUrl + '/listExport';

/**
 * 获取单记录
 * @param pkId
 * @returns {*}
 */
OsUserApi.getOsUser= function(pkId,tenantId) {
  var url= OsUserApi.baseUrl + '/get?pkId=' + pkId ;
  if(tenantId){
    url+="&tenantId="+tenantId;
  }
  return rxAjax.get(url);
}

OsUserApi.edit= function(pkId,groupId,tenantId) {
  var url= OsUserApi.baseUrl + '/edit';
  let ary=[];
  if(pkId){
      ary.push("pkId=" + pkId);
  }
  if(groupId){
    ary.push("groupId=" + groupId);
  }
  if(tenantId){
      ary.push("tenantId=" + tenantId);
  }
  if(ary.length>0){
      url+="?" + ary.join("&");
  }
  return rxAjax.get(url);
}

OsUserApi.getOsUserList= function(parameter) {
  var url= OsUserApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

OsUserApi.getAllOsUserList= function(parameter) {
  var url= OsUserApi.baseUrl + '/getAll';
  return rxAjax.get(url,parameter).then(res => {
    return res.data
  });
}

OsUserApi.saveOsUser= function(parameter) {
  var url= OsUserApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

OsUserApi.delOsUser= function(parameter) {
  var url= OsUserApi.baseUrl + '/del';
  return rxAjax.postUrl(url,parameter);
}

OsUserApi.joinUser= function (parameter) {
  var url= OsUserApi.baseUrl + '/joinUser';
  return rxAjax.postForm(url,parameter);
}

OsUserApi.getUser= function(userId) {
  var url= OsUserApi.baseUrl + '/getById?userId=' + userId;
  return rxAjax.get(url);
}


OsUserApi.dimissionByIds=function(parameter){
  var url = OsUserApi.baseUrl + '/dimissionByIds';
  return rxAjax.postUrl(url,parameter);
}

OsUserApi.updatePassword=function(parameter){
  var url = OsUserApi.baseUrl + '/updatePassword';
  return rxAjax.postUrl(url,parameter);
}

OsUserApi.setPassword=function(parameter){
  var url = OsUserApi.baseUrl + '/setPassword';
  return rxAjax.postUrl(url,parameter);
}

OsUserApi.getDingUser=function(parameter){
  var url = '/api-user/user/ding/syncDdOrgUser';
  return rxAjax.postUrl(url,parameter);
}

OsUserApi.getAll = function () {
  var url = OsUserApi.baseUrl + '/getAll';
  return rxAjax.get(url);
}

OsUserApi.getAdmin = function (tenantId) {
  var url = OsUserApi.baseUrl + '/getAdmin';
  if(tenantId){
    url+="?tenantId=" + tenantId;
  }
  return rxAjax.get(url);
}

OsUserApi.setAdmin = function (userId,admin,tenantId) {
  var url = OsUserApi.baseUrl + '/setAdmin';

  var params={userId:userId,admin:admin};
  if(tenantId){
    params.tenantId=tenantId;
  }

  return rxAjax.postForm(url,params);
}

//导入用户
OsUserApi.importData=function(formData,callback) {
    var url= OsUserApi.baseUrl+"/importData";
    return rxAjax.upload(url,formData,callback);
}

OsUserApi.unlockAccount=function(parameter){
    var url = OsUserApi.baseUrl + '/unlockAccount';
    return rxAjax.postUrl(url,parameter);
}

OsUserApi.getBpmAdminGroup=function(){
    var url = OsUserApi.baseUrl + '/getBpmAdminGroup';
    return rxAjax.get(url);
}

OsUserApi.switchTenantId=function(tenantId){
    var url = OsUserApi.baseUrl + '/switchTenantId';
    let params={tenantId:tenantId};
    return rxAjax.postForm(url,params);
}

//获取当前用户有权限的扩展应用
OsUserApi.getAppByCurUser=function(){
    var url = OsUserApi.baseUrl + '/getAppByCurUser?appType=1';
    return rxAjax.get(url);
}

//获取用户的所有权限
OsUserApi.getOsUserPermission=function(userId){
    var url = OsUserApi.baseUrl + '/getOsUserPermission?userId='+userId;
    return rxAjax.get(url);
}

//获取该用户对应的主部门，用户类型，行政组织，角色，职务
OsUserApi.getOsUserPermissionByUserId= function(userId) {
    var url= OsUserApi.baseUrl + '/getOsUserPermissionByUserId?userId='+userId;
    return rxAjax.get(url);
}

//获取用户某一组ID下的所有权限
OsUserApi.getPermissionsByGroupId=function(groupId){
    var url = OsUserApi.baseUrl + '/getPermissionsByGroupId?groupId='+groupId;
    return rxAjax.get(url);
}

/**
 * 设置用户时区。
 * @param timeZone
 * @returns {*}
 */
OsUserApi.setTimeZone=function(timeZone){
    var url = OsUserApi.baseUrl + '/setTimeZone';
    let params={timeZone:timeZone};
    return rxAjax.postForm(url,params);
}

//获查询当前用户的菜单
OsUserApi.getMenusByAppId=function(appId){
    var url = OsUserApi.baseUrl + '/getMenusByAppId?appId='+appId;
    return rxAjax.get(url);
}

export  default OsUserApi;